package tech.wetech.admin.modules.system.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import tech.wetech.admin.modules.base.query.PageQuery;
import tech.wetech.admin.modules.base.service.impl.BaseService;
import tech.wetech.admin.modules.system.po.ALiPay;
import tech.wetech.admin.modules.system.service.ALiPayService;
import tk.mybatis.mapper.code.Style;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.util.StringUtil;

import java.util.List;

/**
 * @author lu
 * @description
 * @date 2019年09月05日 15:56
 */
@Service
public class ALiPayServiceImpl extends BaseService<ALiPay> implements ALiPayService {
    @Override
    public List<ALiPay> querySelectList(ALiPay aLiPay, PageQuery pageQuery) {
        if (pageQuery.getOrderBy() != null) {
            pageQuery.setOrderBy(StringUtil.convertByStyle(pageQuery.getOrderBy(), Style.camelhump));
        }
        Example example = new Example(ALiPay.class);
        Example.Criteria criteria = example.createCriteria();
        example.setOrderByClause("id DESC");
        if (aLiPay.getOutTradeNo()!=null || aLiPay.getTradeNo()!=null){
            //判断商户订单号是否为空，不为空进行模糊查询
            if (aLiPay.getOutTradeNo()!=null){


                String StrMachNo= aLiPay.getOutTradeNo()+"%";
                // 创建条件对象
                criteria.andLike("outTradeNo",StrMachNo);

            }
            //判断平台订单号是否为空，不为空进行模糊查询
            if (aLiPay.getTradeNo()!=null){


                String StrMachNo= aLiPay.getTradeNo()+"%";
                // 创建条件对象
                criteria.andLike("tradeNo",StrMachNo);

            }
        }
        return PageHelper.startPage(pageQuery)
                .doSelectPage(() -> mapper.selectByExample(example));
    }
}
